<div class="language_selector_wrapper">
<?php
$setLanguageUrl = $html->url(array("plugin"=>"languages","controller"=>"languages",'action'=>'setSelectedLanguage'), true);
App::import("Model","Languages.Language");
$languages = Language::getActiveLangaugeLists();

$defaultLanguage = cr('Config.language');
if(strlen($defaultLanguage) > 2 && stripos($defaultLanguage, "-") !== false)
{
	$defaultLanguage = substr($defaultLanguage, 0, 2);
}
if(isset($session))
{
	if(@$session->read("Config.language"))
	{
		$defaultLanguage = $session->read("Config.language");
	}
}

echo $form->input("languages",array('div'=>false,'label'=>false,"options"=>$languages,'id'=>"language_selector",'value'=>$defaultLanguage));
if(cr('Config.language') && isset($languages[cr('Config.language')]) && $defaultLanguage != cr("Config.language"))
{
	echo $html->link($languages[cr('Config.language')],$setLanguageUrl."/".cr('Config.language'),array("style"=>"font-size:10px;color:#cccccc"));
}
?>
</div>
<script>
	$(document).ready(function(){
		var setLanguageUrl = "<?php echo $setLanguageUrl; ?>";
		$("#language_selector").change(function(){
			var val = $(this).val();
			var referer = "<?php echo "/".$this->params['url']['url']?>";
			if(val)
			{
				window.location = setLanguageUrl+'/'+val+"?referer="+encodeURIComponent(referer);
			}
		});
	})
</script>